import axios from 'axios';

const API_BASE_URL = '/api/administrator'; // 使用代理路径

// 获取班级列表
export const fetchClassList = async (params) => {
    try {
        const response = await axios.get(`${API_BASE_URL}/clazzpage`, {
            params,
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded'
            }
        });
        return response.data;
    } catch (error) {
        throw new Error('Error fetching class list');
    }
};

// 添加班级
export const addClass = async (clazzName) => {
    try {
        const response = await axios.post(`${API_BASE_URL}/addclazz`, { clazzName });
        return response.data;
    } catch (error) {
        throw new Error('Error adding class');
    }
};

// 删除班级
export const deleteClassById = async (id) => {
    try {
        const response = await axios.delete(`${API_BASE_URL}/deleteclazz/${id}`);
        return response.data;
    } catch (error) {
        throw new Error('Error deleting class');
    }
};
